<template>
    <div>
        <!-- 面包屑导航 -->
        <!-- <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>演员管理</el-breadcrumb-item>
            <el-breadcrumb-item>新增演员</el-breadcrumb-item>
        </el-breadcrumb> -->

        <!-- 分割线 -->
        <!-- <el-divider content-position="center"></el-divider> -->
        <el-form ref="form" :rules="rules" :model="form" @submit.native.prevent label-width="80px"
            style="width: 400px;">
            <el-form-item label="姓名" prop="actorName">
                <el-input v-model="form.actorName" placeholder="输入姓名:模糊查询"></el-input>
            </el-form-item>
            <el-form-item label="头像" prop="actorAvatar">
                <el-upload class="avatar-uploader" action="http://localhost:9000/upload" :show-file-list="false"
                    :on-success="handleAvatarSuccess">
                    <img v-if="form.actorAvatar" :src="form.actorAvatar" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">确定添加</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>


    </div>
</template>

<script>
import myaxios from '@/http/MyAxios';
export default {
    data() {
        return {
            form: {
                actorName: '',
                actorAvatar: ''
            },
            rules: {
                actorName: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
                actorAvatar: [{ required: true, message: '请选择一张图片' }]
            }
            //   form.actorName
            //   form[actorName]
        }
    },
    methods: {
        // 文件上传成功的回调
        handleAvatarSuccess(res, file) {
            this.form.actorAvatar = res.data;
        },
        resetForm() {
            this.$refs['form'].resetFields();
        },
        // 提交
        onSubmit() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    this.$http.actorApi.add(this.form).then(res => {
                        if (res.data.code == 200) {
                            this.resetForm()
                            this.$message({
                                message: '新增演员成功',
                                type: 'success'
                            })
                        }
                    }).catch(err => {
                        console.log(err);
                    })
                } else {

                }
            })
        }
    },
}
</script>

<style lang="scss">
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
}

.avatar {
    width: 150px;
    height: 150px;
    display: block;
}
</style>